<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="交易结果" prop="tradeResult">
        <el-select v-model="queryParams.tradeResult" placeholder="请选择交易结果" clearable size="small">
          <el-option v-for="item in tradeResults" :label="item.label" :value="item.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="对账批次" prop="batchNo">
        <el-input
          v-model="queryParams.batchNo"
          placeholder="请输入对账批次"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="交易金额" prop="amount">
        <el-input
          v-model="queryParams.amount"
          placeholder="请输入交易金额"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否差错" prop="hasDiff">
        <el-select v-model="queryParams.hasDiff" placeholder="请选择是否差错" clearable size="small">
          <el-option v-for="item in hasDiffs" :label="item.label" :value="item.value"></el-option>
        </el-select>
      </el-form-item>
      <div>
        <el-form-item label="发起交易日期">
          <div class="block">
            <el-date-picker
              v-model="queryParams.startTime"
              value-format="yyyy-MM-dd HH:mm:ss"
              type="datetime"
              clearable
              placeholder="选择日期时间">
            </el-date-picker>至
            <el-date-picker
              v-model="queryParams.endTime"
              value-format="yyyy-MM-dd HH:mm:ss"
              type="datetime"
              placeholder="选择日期时间"
              clearable>
            </el-date-picker>
          </div>
        </el-form-item>
      </div>
      <el-form-item label="处理结果" prop="processState">
        <el-select v-model="queryParams.processState" placeholder="请选择处理结果" clearable size="small">
          <el-option v-for="item in processStates" :label="item.label" :value="item.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="支付方式" prop="payWay">
        <el-select v-model="queryParams.payWay" placeholder="请选择支付方式" clearable size="small">
          <el-option v-for="item in payWaies" :label="item.label" :value="item.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:detail:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:detail:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:detail:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:detail:export']"
        >导出</el-button>
      </el-col>
	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="detailList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键 自增" align="center" prop="id" />
      <el-table-column label="账期年月日" align="center" prop="billDay" />
      <el-table-column label="对账年月日(yyyymmdd)" align="center" prop="checkDay" />
      <el-table-column label="批次ID" align="center" prop="batchId" />
      <el-table-column label="批次号" align="center" prop="batchNo" />
      <el-table-column label="交易流水号" align="center" prop="payOrderNo" />
      <el-table-column label="渠道订单号" align="center" prop="qudaoOrderNo" />
      <el-table-column label="渠道名称" align="center" prop="tradeQudao" />
      <el-table-column label="记账凭证" align="center" prop="certificateJz" />
      <el-table-column label="对账凭证" align="center" prop="certificateDz" />
      <el-table-column label="交易结果" align="center" prop="tradeResult" >
        <template slot-scope="scope">
          <span v-if="scope.row.tradeResult==1">处理中</span>
          <span v-if="scope.row.tradeResult==2">成功</span>
          <span v-if="scope.row.tradeResult==3">失败</span>
        </template>
      </el-table-column>
      <el-table-column label="交易金额" align="center" prop="amount" />
      <el-table-column label="交易日期" align="center" prop="tradeDateZf" />
      <el-table-column label="支付方式" align="center" prop="payWay" >
        <template slot-scope="scope">
          <span v-if="scope.row.payWay=='1'">微信支付</span>
          <span v-if="scope.row.payWay=='2'">支付宝扫码</span>
          <span v-if="scope.row.payWay=='3'">微信公众号</span>
          <span v-if="scope.row.payWay=='4'">认证支付</span>
          <span v-if="scope.row.payWay=='5'">代付到银行卡</span>
        </template>
      </el-table-column>
      <el-table-column label="交易账户" align="center" prop="tradeAccount">
      </el-table-column>
      <el-table-column label="对账完成时间" align="center" prop="checkEndDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.checkEndDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="差错处理结果出金" align="center" prop="processState" />
      <el-table-column label="是否完成对账" align="center" prop="completeState" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:detail:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:detail:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />


  </div>
</template>

<script>
import { listDetail, getDetail, delDetail, addDetail, updateDetail } from "@/api/finance/detail";

export default {
  name: "Detail",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 对账批次明细（保存对账结果明细的）表格数据
      detailList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        billDay: null,
        checkDay: null,
        batchId: null,
        batchNo: null,
        payOrderNo: null,
        qudaoOrderNo: null,
        tradeQudao: null,
        certificateJz: null,
        certificateDz: null,
        tradeResult: null,
        amount: null,
        tradeDateZf: null,
        commissionFee: null,
        payWay: null,
        tradeAccount: null,
        tradeAccountType: null,
        checkEndDate: null,
        hasDiff: null,
        processState: null,
        completeState: null,
        confirmDate: null,
        canClearingAmount: null,
        remarks: null,
        reserve1: null,
        reserve2: null,
        reserve3: null,
        reserve4: null,
        reserve5: null,
        delFlg: null,
        createUserid: null,
        updateUserid: null,
      },
      // 表单参数
      form: {},
      //交易结果：接口回调或者返回的结果 1:处理中，2:成功，3:失败。
      tradeResults:[
        {label:"处理中",value:"1"},
        {label:"成功",value:"2"},
        {label:"失败",value:"3"}
      ],
      //支付方式,同流水里面一样 1:微信扫码，2:支付宝扫码，3:微信公众号，4:认证支付，5:代付到银行卡
      payWaies:[
        {label:"微信扫码",value:"1"},
        {label:"支付宝支付",value:"2"},
        {label:"微信公众号",value:"3"},
        {label:"认证支付",value:"4"},
        {label:"代付到银行卡",value:"5"}
      ],
      //是否差错
      hasDiffs:[
        {label:"否",value:"0"},
        {label:"是",value:"1"},
      ],
      //处理结果
      processStates:[
        {label:"未处理",value:"1"},
        {label:"要结算",value:"2"},
        {label:"不结算",value:"3"},
        {label:"已处理",value:"4"},
      ],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询对账批次明细（保存对账结果明细的）列表 */
    getList() {
      this.loading = true;
      listDetail(this.queryParams).then(response => {
        this.detailList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        billDay: null,
        checkDay: null,
        batchId: null,
        batchNo: null,
        payOrderNo: null,
        qudaoOrderNo: null,
        tradeQudao: null,
        certificateJz: null,
        certificateDz: null,
        tradeResult: null,
        amount: null,
        tradeDateZf: null,
        commissionFee: null,
        payWay: null,
        tradeAccount: null,
        tradeAccountType: null,
        checkEndDate: null,
        hasDiff: null,
        processState: null,
        completeState: null,
        confirmDate: null,
        canClearingAmount: null,
        remarks: null,
        reserve1: null,
        reserve2: null,
        reserve3: null,
        reserve4: null,
        reserve5: null,
        delFlg: null,
        createUserid: null,
        createTime: null,
        updateUserid: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加对账批次明细（保存对账结果明细的）";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getDetail(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改对账批次明细（保存对账结果明细的）";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateDetail(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDetail(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除对账批次明细（保存对账结果明细的）编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delDetail(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/detail/export', {
        ...this.queryParams
      }, `system_detail.xlsx`)
    }
  }
};
</script>
